package com.bite.system.controller.sysuser;

import com.bite.common.core.constants.HttpConstants;
import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.vo.LoginUserVO;
import com.bite.common.security.service.TokenService;
import com.bite.system.domain.sysuser.dto.LoginDTO;
import com.bite.system.domain.sysuser.dto.SysUserSaveDTO;
import com.bite.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "管理员接口")//给接口分组
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {



    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private TokenService tokenService;


    /*
    swagger中的注解
    * @ApiResponse->⽤于描述操作的响应结果
    * @Operation->描述接口
    *  @Parameter->描述输入参数
    * */

    //登陆成功还是失败，如果失败告诉原因（管理员登陆）
    //请求方法->url  /sysUser/login
    @ApiResponse(responseCode = "1000", description = "操作成功")//⽤于描述操作的响应结果
    @ApiResponse(responseCode = "2000", description = "服务器繁忙稍后重试")
    @ApiResponse(responseCode = "1000", description = "用户不存在")
    @Operation(summary = "管理员登陆", description = "根据用户名和密码进行登陆")//描述接口
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }



    //增加管理员
    @ApiResponse(responseCode = "1000", description = "操作成功")//⽤于描述操作的响应结果
    @ApiResponse(responseCode = "2000", description = "服务器繁忙稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "新增管理员")//描述接口
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toR(sysUserService.add(sysUserSaveDTO));
    }


    @DeleteMapping("/{userId}")
    @Operation(summary = "删除⽤⼾", description = "通过⽤⼾id删除⽤⼾")
    @Parameters(value = {@Parameter(name = "userId", in = ParameterIn.PATH, description = "⽤⼾ID")})
    @ApiResponse(responseCode = "1000", description = "成功删除⽤⼾")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")//>描述输入参数
    @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
    public R<Void> delete(@PathVariable Long userId) {
        return null;
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION)String token){
        return toR(sysUserService.logout(token));
    }



    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION)  String token){
        return sysUserService.info(token);
    }



    /*@Operation(summary = "⽤⼾详情", description = "根据查询条件查询⽤⼾详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "⽤⼾性别")
                    })
            @ApiResponse(responseCode = "1000", description = "成功获取⽤⼾信息")
            @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
            @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
            public R<SysUserVO>detail(Long userId, @RequestParam(required = false)String sex) {
        return null;
    }*/

}
